package com.twu.biblioteca;

import java.io.PrintStream;
import java.util.Collection;

/**
 * Created with IntelliJ IDEA.
 * User: thoughtworker
 * Date: 10/9/13
 * Time: 9:32 AM
 * To change this template use File | Settings | File Templates.
 */
public class Library {

    private Collection<Book> listOfBooks;

    public Library() {
        this.listOfBooks = bookRepository.getBooks();
    }

    public void printBookTitle(PrintStream printStream) {
        for(Book book:listOfBooks) {
            printStream.println(book.getTitle());
        }
    }

    public boolean checkBookIsInLibrary(String bookToFind) {
        return listOfBooks.contains(bookToFind);
    }

    public boolean checkBookReservation(String bookToCheckReservation) {
        return findBook(bookToCheckReservation).isTheBookReserved();
    }

    public Book findBook(String bookToFind) {
        for(Book book : listOfBooks) {
            if (book.getTitle().equals(bookToFind)) return book;
        }
        return null;
    }

    public void reserveBook(String bookToReserve) {
        findBook(bookToReserve).reserve();
    }
}
